package cn.example.vip.mall.seckill.rocketmq;

import cn.example.vip.mall.seckill.service.SeckillOrderService;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * RocketMQ监听配置,设置主题监听，消费组
 */
@RocketMQMessageListener(
	topic = "order-queue",
	consumerGroup = "orderqueue-consumer",
	selectorExpression = "*"
)
@Component
public class OrderQueueListener implements RocketMQListener {
	@Autowired
	private SeckillOrderService seckillOrderService;
	
	/**
	 * 监听消息
	 * @param o
	 */
	@Override
	public void onMessage(Object o/*message*/) {
		seckillOrderService.addOrder(JSON.parseObject(o.toString(), Map.class));
		
	}
}
